<?php

namespace post\modules\post\controllers;


use post\modules\post\models\Comment;
use post\modules\post\models\Post;
use post\modules\post\models\Zan;
use Yii;

use yii\data\Pagination;
use yii\web\Controller;
use post\base\BaseController;
class CommentPostController extends BaseController {


    public function  beforeAction($action)
    {
        $request=Yii::$app->request;
        if($request->isGet){

            echo "请求错误";
            return false;

        }

        return parent::beforeAction($action);

    }
    public function  actionAdd()
    {


        $data_info=['content','post_id'];
        $data=$this->data_validate($data_info);

        if($data=="false")
        {
            return $this->json_error("参数不全");
        }
        $user_id=$this->getUserId();

        $comment=new Comment();
        $comment->user_id=$user_id;
        $comment->post_id=$data['post_id'];
        $comment->content=$data['content'];
        $comment->save();

        if($comment)
        {
            Yii::$app->redis->flushall();
            return $this->json_ok("成功--OK!");
        }else{

            return $this->json_error("失败--ERROR!");
        }

    }




}
